package com.cyw.baselibrary.utils;

import android.text.TextUtils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 正则工具
 * Created by ChenYuanWang on 2019-01-22.
 */
public class RegularUtils {

    private static String patternCoder = "(?<!\\d)\\d{6}(?!\\d)";

    /**
     * 提取验证码
     *
     * @param patternContent
     * @return
     */
    public static String patternCode(String patternContent) {
        if (TextUtils.isEmpty(patternContent) || !patternContent.contains("验证码")) {
            return null;
        }
        Pattern p = Pattern.compile(patternCoder);
        Matcher matcher = p.matcher(patternContent);
        if (matcher.find()) {
            return matcher.group();
        }
        return null;
    }
}
